package com.zrrd.learn.chapter04;

/**
 * 斐波那契数列
 *
 * @author wrn
 * @version 1.0
 * @date 2023/5/27 14:38
 */

public class FBNQ {

    public static void main(String[] args) {
        System.out.println(fibonacci(3));

    }

    /**
     * 循环打印
     * @param count
     */

    public  static  void printFBNQ(int count){
        long start = 1;
        long second = 1;
        System.out.print(start + "\t" );
        System.out.print(second + "\t" );
        int index = 2;
        while (index++ < count) {
            long t = start + second;
            System.out.print(start + second + "\t");
            start = second;
            second = t;
        }
    }

    /**
     * 递归
     * @param a 位置
     * @return  数
     */
    public static  int fibonacci(int a){
        int num=0;
        if (a==1||a==2){
            num=1;
            return num;
        }else {
            return fibonacci(a-1) + fibonacci( a-2);
        }
    }

}
